﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication1.Domain.Entity;

namespace WebApplication1.Domain
{
    public class DbInitializeHelper
    {
        public static void Initilzer()
        {
            using(var db=new Admin400DbContext())
            {
                db.Database.EnsureCreated();
                var tempBrand = db.Brands.Any();

                if (!tempBrand)
                {

                    var brand = new Brand
                    {
                        BrandName = "双倍辣火鸡面",
                        Description = "可以辣死你的那种"
                    };

                    db.Brands.Add(brand);

                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                        {
                        new Product
                        {
                            ProductName="双倍辣火鸡面",
                            ShortDesc="带着刺激味道的简介",
                            FullDesc="这是个辣辣的详情",
                            BrandId=brand.Id
                        },new Product
                        {
                             ProductName="双倍辣火鸡面",
                            ShortDesc="一个辣到拉肚子的简介",
                            FullDesc="这是很辣很辣的详情",
                            BrandId=brand.Id
                        }
                        });
                    db.SaveChanges();

                }
            }
        }
    }
}
